// components/tab-bar/index.js
const app = getApp()

Component({
    properties: {
        hideList: {
            type: Array,
            value: []
        }
    },
    options: {
        addGlobalClass: true
    },
    data: {
        route: '',
        shows: {
            index: true,
            shop: true,
            qsgc: true,
            mirror: true,
            toop: true,
            balance: true,
            msz: true,
        }
    },
    lifetimes: {
        attached() {
            const pages = getCurrentPages()
            const len = pages.length
            const ctx = pages[len - 1]
            console.log(ctx.route)
            let route = ctx.route
            let shows = this.data.shows
            const hideList = this.data.hideList

            if (route.includes('mirror')) {
                if (route.includes('qsgc-index')) {
                    route = 'mirror-qsgc'
                } else {
                    route = 'mirror'
                }
            } else {
                route = ctx.route.split('/')[0]
                if (route.includes('package-')) {
                    route = route.split('package-')[1]
                }
            }
            console.log(route)

            if (route === 'mirror-qsgc' || hideList.includes('qsgc')) {
                shows.qsgc = false
            } else if (route === 'mirror' || hideList.includes('mirror')) {
                shows.mirror = false
            } else if (route === 'mirror') {
                shows.mirror = false
            } else {
                shows[route] = false
            }
            if (route === 'pages' || hideList.includes('shop')) {
                shows.shop = false
            }
            if (hideList.includes(route)) {
                shows[route] = false
            }
            for (let key of hideList) {
                shows[key] = false
            }
            this.setData({
                route,
                shows
            })
        },
        detached() {
            // 在组件实例被从页面节点树移除时执行
        },
    },
    methods: {
        scanCode() {
            app.scanCode()
        },
    }
})
